#include "main_file.h"
#include <asm/uaccess.h>
#include "linux_gpio.h"
#include "main.h"
int dev_open(struct inode *inode, struct file *filp)
{
    charDeviceStruct* device;
    filp->private_data = ledgpio;
    device =(charDeviceStruct*) filp->private_data;
    printk("dev open %s\n",device->name);
    return 0;
}
int dev_release(struct inode *inode, struct file *filp)
{
    return 0;
}
ssize_t dev_read(struct file *filp, char __user *buf,size_t cnt, loff_t *offt)
{
    // uint8_t status =2;
    // ssize_t ret;
    // charDeviceStruct *dev =(charDeviceStruct *) filp->private_data;
    // status = gpio_get_value(dev->treeInfo.gpio_index);   
    // printk("LED read  index:%d value:%d\n",dev->treeInfo.gpio_index,status); 
    // ret = copy_to_user(buf, &status, 1);
     return 0;
}
ssize_t dev_write(struct file *filp, const char __user *buf,size_t cnt, loff_t *offt)
{
    int retvalue;
    char databuf[1];
    charDeviceStruct *dev =(charDeviceStruct *) filp->private_data;
    
    retvalue = copy_from_user(databuf, buf, cnt);
    if(retvalue < 0) {
        printk("copy_from_user;kernel write failed!\r\n");
    return -EFAULT;
    }
    //printk("LED write index:%d value:%d\n",dev->treeInfo.gpio_index,databuf[0]);
    if(databuf[0] == GPIO_SET || databuf[0] == GPIO_RESET) gpio_set_value(dev->treeInfo.gpio_index,*buf); 
    else {
        printk("parameter is error = %d\r\n",databuf[0]);
    }
    return 0;
}
